﻿using EnetaMvc.Core.Domain.Content;
using EnetaMvc.Core.Domain.SLA;
using EnetaMvc.Core.Repositories;
using EnetaMvc.Infrastructure;
using NHibernate;
using NHibernate.Criterion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EnetaMvc.Data.NHibernate.Repositories
{
    public class SlaMonitoringLogRepository : BaseRepository, ISlaMonitoringLogRepository
    {
        private readonly ISession _session;

        public SlaMonitoringLogRepository(IMapperSession session)
            : base(((NHSession)session).GetCurrentSession())
        {
            _session = ((NHSession)session).GetCurrentSession();
        }

        public PagedResult<T> ListSlaLogs<T>(int page, int pageSize) where T : Core.Domain.SLA.SlaMonitoringLog
        {
            var criteria = _session.CreateCriteria<T>()
                                    .AddOrder(Order.Desc("NewStateDate"));
            return GetPagedResultForQuery<T>(criteria, page, pageSize);
        }

        public T GetById<T>(long id) where T : SlaMonitoringLog
        {
            return _session.Get<T>(id);
        }

        public void SaveSlaLog(SlaMonitoringLog slaLog)
        {
            if (slaLog == null)
                return;

            SaveInTransaction(slaLog);
        }
    }
}
